using System;
using System.Collections.Generic;
using System.Text;
using Barrage;
using Spacedash.Logic;
using SlimDX;
using Barrage.GUI.Meshes;
using Barrage.Textures;
using Barrage.Shaders;
using Barrage.Global;
using Barrage.Elements;

namespace Spacedash.Game.Items
{
    /// <summary>
    /// Node that renders a minimap on screen
    /// </summary>
    public class GUIMinimap : Node
    {
        Race race;
        Ship ship;

        /// <summary>
        /// Width of the minimap
        /// </summary>
        public const float SIZE_X = 96;
        /// <summary>
        /// Height of the minimap
        /// </summary>
        public const float SIZE_Y = 740;
        /// <summary>
        /// Margin of the minimap
        /// </summary>
        public const float MARGIN = 24;

        const float COORD_BORDER_X = 34;
        const float COORD_BORDER_Y = 34;
        const float UV_BORDER_X = 0.354166f;
        const float UV_BORDER_Y = 0.04427083f;
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="pos">Minimap position on screen</param>
        /// <param name="race">Race instance</param>
        /// <param name="ship">Ship associated to this minimap (its icon is bigger)</param>
        public GUIMinimap(Vector2 pos, Race race,Ship ship)
        {
            this.race = race;
            this.ship = ship;
            motion.Translation = new Vector3(pos, 0);

            Item i = new Item(new BorderedRectangle(TextureManager.Textures["GUI/Minimap_BG.png"], new Vector2(SIZE_X, SIZE_Y), new float[] { COORD_BORDER_X, COORD_BORDER_Y, COORD_BORDER_X, COORD_BORDER_Y }, new float[] { UV_BORDER_X, UV_BORDER_Y, UV_BORDER_X, UV_BORDER_Y }));
            addElement(i);

            foreach (Ship s in race.Ships)
            {
                if (s != ship)
                {
                    i = new GUIMinimapCursor(race, s);
                    i.Motion.Translation = new Vector3(16, 0, 0);
                    i.Motion.Scale = new Vector3(0.5f, 0.5f, 1);
                    addElement(i);
                }
            }

            i = new GUIMinimapCursor(race, ship);
            i.Motion.Translation = new Vector3(32, 0, 0);            
            addElement(i);
        }

    }
}
